package com.ydkfjs.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.ydkfjs.common.Result;
import com.ydkfjs.model.dto.LoginRequest;
import com.ydkfjs.service.LoginService;


//import io.swagger.v3.oas.annotations.Operation;
//import io.swagger.v3.oas.annotations.tags.Tag;
//import jakarta.validation.Valid;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
//import javax.validation.Valid;
import java.util.Map;

/**
 * @Author: hb
 * @CreateTime: 2024-04-02 11:21
 * @Version: 1.0
 */
@Api(tags = "登录模块")
@RestController
@RequestMapping("/login")
public class LoginController {

    private final LoginService loginService;

    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    @ApiOperation(value = "登录")
    @PostMapping("/phone")
    public Result<Map<String, String>> loginByPhone(@RequestBody LoginRequest loginRequest,HttpServletRequest request) {
        Map<String, String> ajax = loginService.login(loginRequest, request);
        return Result.success("登录成功", ajax);
    }

    @ApiOperation(value = "退出登录")
    @PostMapping("/logout")
    public Result<Void> logout(HttpServletRequest request) {
        StpUtil.logout();
        return Result.success();
    }


}
